﻿#region copyright info
//------------------------------------------------------------------------------
// <copyright company="ChaosStudio">
//     Copyright (c) 2002-2010 巧思工作室.  All rights reserved.
//     Contact:		MSN:zhouyu@cszi.com , QQ:478779122
//		Link:				http://www.69sea.com http://www.cszi.com
// </copyright>
//------------------------------------------------------------------------------
#endregion

using System;
using System.Threading;
using CS.WinService;
using log4net;

namespace CS.TaskScheduling
{
    /// <summary>
    ///   任务实现示例
    /// </summary>
    /// 
    /// <description class = "CS.WinService.TaskDemo">
    ///   
    /// </description>
    /// 
    /// <history>
    ///   2010-4-23 10:22:02 , zhouyu ,  创建	     
    ///  </history>
    public class TaskDemo:TaskProvider
    {
        private readonly ILog _logWork = LogManager.GetLogger();


        private static readonly Random rand = new Random();
        protected static int RandSeconds()
        {
            return rand.Next(2000, 6000);
        }


        protected override Result Work()
        {
            var stamp = ResultType.Succeed;
            var rs = RandSeconds();
            if (rs > 4500)
                stamp = ResultType.Failed;

            Thread.Sleep(rs );

            _logWork.InfoFormat("我是执行的任务,工作了{0}秒", rs / 1000);

            return new Result() { Stamp = stamp };
        }


        /// <summary>
        /// 如扩展配置时一定要重写本方法
        /// </summary>
        public override void LoadExtendConfig()
        {
            base.LoadExtendConfig();   //默认时启用系统中的公共扩展
        }
    }
}
